(library (graph-grammar)
  (export Y
          X
          COORDS
          NODE-NAME
          NODE
          ASSOC-NODE-NAME
          SOURCE-NODE-NAME
          TARGET-NODE-NAME
          WEIGHT
          ASSOCIATION)
  (import (except (rnrs base)
                  let-values
                  map
                  error
                  vector-map)
          (only (guile)
                lambda* λ)

   ;; standard library
   (ice-9 peg)
   (grammar-basics))

  (define-peg-pattern Y all NUMBER)
  (define-peg-pattern X all NUMBER)
  (define-peg-pattern COORDS all (and Y COMMA X))
  (define-peg-pattern NODE-NAME all (+ ANYTHING-EXCEPT-SPACE))
  (define-peg-pattern NODE all (and NODE-NAME SPACE COORDS))

  (define-peg-pattern ASSOC-NODE-NAME body (+ ANYTHING-EXCEPT-SPACE))
  (define-peg-pattern SOURCE-NODE-NAME all ASSOC-NODE-NAME)
  (define-peg-pattern TARGET-NODE-NAME all ASSOC-NODE-NAME)
  (define-peg-pattern WEIGHT all NUMBER)

  (define-peg-pattern ASSOCIATION all
    (and SOURCE-NODE-NAME SPACE
         ARROW SPACE
         TARGET-NODE-NAME SPACE
         WEIGHT)))
